﻿<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  <meta name="format-detection" content="telephone=no" />
  <title>标签</title>
  <link rel="stylesheet" type="text/css" href="../plugins/weui/css/weui.min.css">
  <link rel="stylesheet" type="text/css" href="../css/base.css">
  <link rel="stylesheet" type="text/css" href="../css/css.css">
    <style media="screen">
        .weui-cells {
            margin-top: 0px;
        }

        .header {
            background-color: #F0EEF4;
            color: #7F7E83;
            font-size: 14px;
        }
    </style>
</head>

<body>
  <div class="container">
    <div class="weui-cells header">
      <div class="weui-cell ">
        <div class="weui-cell__bd">
          <p>标签名字</p>
        </div>
      </div>
    </div>
    <div class="weui-cells">
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <input type="text" id="tagname" class="weui-search-bar__input" style="width:100%;height:30px;border:0;background-color: #fff;" />
        </div>
    </div>
</div>
<div class="weui-cells header">
  <div class="weui-cell ">
    <div class="weui-cell__bd">
      <p>标签成员(<span id="tagnum"></span>)</p>
    </div>
  </div>
</div>
<div class="weui-cells wess">
</div>
  </div>
    <script type="text/javascript" src="../js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="../js/base.js"></script>
    <script type="text/javascript">
        var addId = 0;
        $(function () {
            if (getQueryString("Id") != '') {
                $('#tagname').attr("disabled", "disabled");
                ajaxGet(siteApiList.GetTagRelationListById + "?Id=" + getQueryString("Id"), function (res) {
                    $('.wess').html(function () {
                        var arr = [];

                        arr.push('<a class="weui-cell weui-cell_access" href="addemployee.html?clientTagid=' + getQueryString("Id") + '"><div class="weui-cell__hd"><img src="../images/pk/111.png" alt="" style="width:20px;margin-right:10px;display:block;"></div><div class="weui-cell__bd"><p style="color:#496DA4" >添加成员</p></div></a>');
                        $.each(res.Data.crList, function (index, item) {
                            console.log(item.Avatar)
                            arr.push('<a class="weui-cell weui-cell_access" attrid="' + item.Clientid + '" href="' + siteUrlList.customerDetail + "?clientid=" + item.Clientid + "&staffId=" + item.StaffId + '"><div class="weui-cell__hd"><img src="'
                                + siteConfig.formatAvater(item.Avatar)
                                + '" alt="" style="width:32px;height: 32px;margin-right:10px;display:block;"></div><div class="weui-cell__bd weui-Detail"><p>' + item.NickName + '</p></div></a>');
                        });
                        return arr.join('');
                        //clientid = item.StaffId;
                        //staffId = item.Clientid;
                    });
                    $('#tagnum').html(res.Data.crList.length);
                    $('#tagname').val(res.Data.ctList.TagName);

                })
            } else {
                $('.wess').html(function () {
                    var arr = [];
                    arr.push('<a class="weui-cell weui-cell_access" id="addId" href="javascript:CheckInput();"><div class="weui-cell__hd"><img src="../images/pk/111.png" alt="" style="width:20px;margin-right:10px;display:block;"></div><div class="weui-cell__bd"><p style="color:#496DA4" >添加成员</p></div></a>');
                    return arr.join('');
                });
                $('#tagnum').html(0);

                loadBtn();
            }
        });

        function loadBtn() {
            $('#tagname').on('blur', function () {
                var tagname = $('#tagname').val();
                if (tagname == '') return;
                if (getQueryString("Id") == '') {
                    ajaxPost(siteApiList.AddClientTag, "staffId=0&categoryId=100&tagname=" + tagname, function (res) {
                        if (!isJsonSuccess(res))
                            return;
                        $('#addId').attr('href', 'addemployee.html?clientTagid='+res.Data);
                    });
                } else {
                    ajaxPost(siteApiList.UpdateClientTag, "Id=" + getQueryString('Id') + "&tagname=" + tagname, function (res) {
                        if (!isJsonSuccess(res))
                            return;
                    });
                }
            });
        }

        function CheckInput() {
            var tagname = $('#tagname').val();
            if ($.trim(tagname) == '')
                Alert('请先输入标签名');
        }
       
    </script>



</body>

</html>
